/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.unmsm.cinfo.siga.ui.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.jdesktop.beansbinding.Converter;
/**
 *
 * @author lartkma
 */
public class DateToHoraConverter extends Converter<Date, Hora> {

    private static DateToHoraConverter that = null;

    private DateToHoraConverter() {
    }
    
    @Override
    public Hora convertForward(Date value) {
        Calendar c = GregorianCalendar.getInstance();
        c.setTime(value);
        return new Hora(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
    }

    @Override
    public Date convertReverse(Hora value) {
        Calendar c = GregorianCalendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, value.getHoras());
        c.set(Calendar.MINUTE, value.getMinutos());
        return c.getTime();
    }
    
    public static DateToHoraConverter get(){
        if(that == null) that = new DateToHoraConverter();
        return that;
    }
    
}
